package com.qrxs.os.view

import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.base.core.BaseModuleActivity
import com.kongzue.dialog.v3.MessageDialog
import com.kongzue.dialog.v3.WaitDialog
import com.lib.base.router.xsos.XSPath
import com.lib.base.utils.ViewModelUtils
import com.qrxs.os.R
import com.qrxs.os.data.viewmodel.LoginViewModel
import kotlinx.android.synthetic.main.xsos_activity_login.*

@Route(path = XSPath.LOGIN, extras = 101)
class LoginActivity : BaseModuleActivity() {

    /**  布局id---2019-06-13 */
    override val layoutId: Int?
        get() = R.layout.xsos_activity_login

    private lateinit var model: LoginViewModel
    /**获取数据*/
    override fun getData() {
    }

    override fun initView() {


        xsos_login.setOnClickListener {

            if (TextUtils.isEmpty(xsos_phone.text.toString()) || TextUtils.isEmpty(xsos_pwd.text.toString())) {
                showToast("必填项")
                return@setOnClickListener
            }

            WaitDialog.show(this, "请求中...").cancelable = true
            model.login(xsos_phone.text.toString(), xsos_pwd.text.toString(), "测试", "192.168.1.1", "1.0", "101010")
        }


        model = ViewModelUtils.getModel(this, LoginViewModel::class.java)
        model.userData.observe(this as AppCompatActivity, Observer {
            WaitDialog.dismiss()
            MessageDialog.build(this).setMessage("$it").show()
        })
    }
}
